import API from './api'

import request from '../utils/request'

// 异步登陆 根据用户名和密码匹配用户
export const loginAsync = (user) => request({
  url: API.USER_API,
  method: 'GET',
  params: {
    username: user.username,
    password: user.password,
    _expand: 'menu',
  },
})

// 自动填入账户 根据 token 匹配
export const loginTokenGET = (tokenStr) => request({
  url: API.USER_API,
  method: 'GET',
  params: {
    token: tokenStr,
  },
})

// 获取所有员工的总数
export const getStaffsLength = ({...options} = {}) => request({
  url: API.USER_API,
  method: 'GET',
  params: {
    ...options,
  },
}).then((data) => data.length)
  .catch((err) => {
    console.log(err)
  })

// 查询员工数据终极版
export const getStaffsUltimate = ({_page = 1, _limit = 3, ...otherOptions} = {}) => request({
  url: API.USER_API,
  method: 'GET',
  params: {
    _page,
    _limit,
    ...otherOptions,
  },
})

// 获取指定ID的员工数据
export const getStaffOfId = (id) => request({
  url: API.USER_API + '/' + id,
  method: 'GET',
})
